package com.qst.express.utils.read;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelReader;
import com.alibaba.excel.read.listener.PageReadListener;
import com.alibaba.excel.read.metadata.ReadSheet;
import com.qst.express.Listener.ExcleListener;
import com.qst.express.utils.DataDemo;
import com.qst.express.utils.DataDemoService;
import com.qst.express.utils.TestFileUtil;
import org.junit.jupiter.api.Test;

/**
 * @author:CoolTiger
 * @title: SimpleReader
 * @projectName springboot-e
 * @description: TODO
 * @date:2023/10/23/21:21:28
 **/
public class SimpleReader {
    public static void main(String[] args) {
        String fileName = TestFileUtil.getPath()+"1.xlsx";
        ExcelReader reader = EasyExcel.read(fileName, DataDemo.class, new ExcleListener(new DataDemoService())).build();
        ReadSheet sheet = EasyExcel.readSheet().build();
        reader.read(sheet);
    }
    @Test
    public void read(){
        String fileName = TestFileUtil.getPath() +"1.xlsx";
        System.out.println(fileName);
        // 这里默认每次会读取100条数据 然后返回过来 直接调用使用数据就行
        // 具体需要返回多少行可以在`PageReadListener`的构造函数设置
        EasyExcel.read(fileName, DataDemo.class, new PageReadListener<DataDemo>(dataList -> {
            for (DataDemo demoData : dataList) {
                System.out.println(demoData);
            }
        })).sheet().doRead();
    }



    @Test
    public void read2(){
        String fileName = TestFileUtil.getPath()+"1.xlsx";
        ExcelReader reader = EasyExcel.read(fileName, DataDemo.class, new ExcleListener(new DataDemoService())).build();
        ReadSheet sheet = EasyExcel.readSheet().build();
        reader.read(sheet);
    }

}
